<%@ page language="java" contentType="text/html; charset=Shift_JIS"
    pageEncoding="Shift_JIS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>Insert title here</title>
</head>
<body>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="java.sql.*" %>
<%@ page import ="java.util.Date" %>

<%
out.println("I am in jsp");
out.write("<tr>");
String name = request.getParameter("name");
out.println(name);
out.write("</tr>");
out.println(request.getParameter("pwd"));

DataSource datasource=null;
InitialContext initialContext = new InitialContext();
Context context = (Context)initialContext.lookup("java:/comp/env");
datasource = (DataSource)context.lookup("jdbc/morph-ds");
Connection dbConnection = datasource.getConnection();
//out.println(dbConnection.getClientInfo().getProperty("dbname"));

Statement stmt= dbConnection.createStatement();
try{
	 // String command = "CREATE TABLE IF NOT EXISTS Test000000 (Name CHAR(10), Time CHAR(50));";
	 // stmt.executeUpdate(command);
	
     // command = "INSERT INTO Test000000 (Name, Time) VALUES ('"+name+"', new Date().toString())";
     // stmt.executeUpdate(command);
	
    // ResultSet rs=stmt.executeQuery("select * from Test000000");
    ResultSet rs=stmt.executeQuery("SELECT 'DB Connect successfully,Hello World from DB'");	
	while (rs.next()){
%>
	<%=rs.getString(1)%>
	<%}%>
<%	

	// stmt.executeUpdate("DROP TABLE IF EXIST Test000000");
	rs.close();
	stmt.close();
	dbConnection.close();
	}catch(SQLException se){
		se.printStackTrace();
	}finally{
		   try {
		       if (stmt != null){
		    	  // stmt.executeUpdate("DROP TABLE IF EXIST Test000000");
		    	   stmt.close();
		       }
		       }  catch (SQLException e) {}
		       try {
		        if (dbConnection != null)
		        	dbConnection.close();
		        } catch (SQLException e) {}
	}
%>
</body>
</html>